from manimlib import *
from numpy import square
import numpy as np

class Test(Scene):
    #75cfb8
    #浅绿
    #bbdfc8
    #浅黄
    #f0e5d8
    #深黄
    #ffc478
    def construct(self):
        # self.add(NumberPlane())
        x=Tex('x',color=BLACK).shift(UP)
        p1=Polygon(ORIGIN,[2,0,0],[1.1,2,0],color='#75cfb8').next_to(x,LEFT*2)
        p2=p1.copy().scale(2).next_to(x,RIGHT)
        self.add(x,Tex(r'\sim',color=BLACK).next_to(x,DOWN),p1,p2)
        self.add(Tex('A_1',color=BLACK).next_to(p1,LEFT),Tex('A_2',color=BLACK).next_to(p2,RIGHT),Tex('b',color=BLACK).next_to(p1,DOWN),Tex('xb',color=BLACK).next_to(p2,DOWN))
        t1=Tex(r'\frac{A_2}{A_1}=x^2',color=BLACK).shift(DOWN*2.5)
        self.add(t1)
        self.wait(0.03)
        self.remove(t1)
        self.add(Tex(r'A_1=\frac{bh}{2}',color=BLACK).shift(DOWN*2.5+LEFT*2),Tex(r'A_2=\frac{xb\cdot xh}{2}',color=BLACK).shift(DOWN*2.5+RIGHT*2))
        d1=DashedLine([-1.52,2,0],[-1.52,0,0],color=BLACK)
        d2=DashedLine([2.58,3,0],[2.58,-1,0],color=BLACK)
        self.add(Tex('h',color=BLACK).next_to(d1,RIGHT,buff=0.1),Tex('xh',color=BLACK).next_to(d2,RIGHT,buff=0.1))
        a1=Angle(Line(LEFT,ORIGIN),Line([-1.52,0,0],[-1.52,2,0]),color=BLACK,elbow=True)
        a2=Angle(Line([0,-1,0],[5,-1,0]),Line([2.58,-1,0],[2.58,3,0]),color=BLACK,elbow=True)
        self.add(d1,d2,a1,a2)
        self.wait(0.03)
        # self.wait(1)